#ifndef ANATOMICALTEMPLATE_H
#define ANATOMICALTEMPLATE_H
#include <vector>
#include <string>
#include <regioninfo.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <QObject>
#include <QVector>
#include <QPoint>
#include <vtkPolyDataCollection.h>
#include <vtkActorCollection.h>
#include <vtkMapperCollection.h>
#include <vtkRenderer.h>
//#include <hdrImageReader.h>
#include <anatomicalregion.h>
#include <anatomicallink.h>
#include <vtkOutlineFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkAppendPolyData.h>

enum BrainHalf
{
    Left,
    Right,
    Both
};

class AnatomicalTemplate : public QObject
{
    Q_OBJECT

signals:
    void taskUpdate(int current, int max);

public:
    AnatomicalTemplate(int expectedROIs);
    AnatomicalTemplate();

    void loadNamesFromFile(std::string filepath);
    void loadCoordinatesFromFile(std::string filepath);
    void load3DdataFromHdrFile(std::string filepath);
	void load3DdataFromVTIFiles(std::string folderpath);
    void attachToRenderer(vtkRenderer *renderer);
    void detachFromRenderer(vtkRenderer *renderer);
    int getNumberOfROIs();
    void setNumberOfROIs(int n);
    AnatomicalRegion *getRegion(int i);
	AnatomicalRegion *getRegionById(int id);
    double getDistance(AnatomicalRegion *r1, AnatomicalRegion *r2);
    QPoint getMatrixIndex(int index);
    int getCollectionIndex(int row, int col);

    //void setSelection(const QVector<AnatomicalRegion*>& select);
    //void setSelection(const QVector<AnatomicalLink*>& select);

    double* getCenterOfLobe(int lobe, BrainHalf half);
	vtkActor* getOutlineActor();
	
	QVector<AnatomicalRegion*> & getRegions() const;

private:
    double calculateDistance(AnatomicalRegion *r1, AnatomicalRegion *r2);
	void createOutlineActor(vtkDataSet *data);

    int expectedROIs;
    QVector<AnatomicalRegion*> RegionList;
    QVector<double> Distances;
    vtkDataSet* data;

	vtkActor* actor;
	vtkPolyDataMapper* mapper;
};

#endif // ANATOMICALTEMPLATE_H
